﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ServiceStack.Text;
using Framework.Library.Core.Provider.Payment;
using Framework.Library.Core.Config;
using Framework.Library.Base.Extensions;

namespace Framework.Portal.Payment
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Xử lý để lấy thông tin access token lưu vào session
            if (!string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                VcoinService vcoin = new VcoinService();
                //Xử lý đoạn code nhận được
                string _code = Request.QueryString["code"];
                KeyAccess info = vcoin.GetAccess_token(_code);
                if (info != null)
                {                    
                    Context.Session.SetPrincipal(new Principal()
                    {
                        AccountId = Convert.ToInt64(info.UserId),
                        Username = info.User,
                        LastAction =
                            DateTime.Now.AddMilliseconds(-5).Ticks,
                        Code = info.code,
                        AccessToken = info.access_token,
                        ExpriseTime = info.expires
                    });
                    Session["abcxyz"] = info.access_token;
                }
                if (!string.IsNullOrEmpty(Request.QueryString["urlreturn"]))
                    Response.Redirect(HttpUtility.UrlDecode(Request.QueryString["urlreturn"]));
                else
                    Response.Redirect(Configurations.ROOTDIR);
            }
        }
    }
}